package com.ctc.test.serial;

import java.io.File;

/**
 * 串口类
 */
public class SerialPortBean {

    /*
        {
            name='ttyS3',
            root='rk_serial',
            file=/dev/ttyS3
        }
     */

    private String name;

    private String root;

    private File file;

    public SerialPortBean() {}

    public SerialPortBean(String name, String root, File file) {
        this.name = name;
        this.root = root;
        this.file = file;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRoot() {
        return root;
    }

    public void setRoot(String root) {
        this.root = root;
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    /**
     * 获取串口地址
     */
    public String getPath() {
        if (file != null && file.exists()) {
            return file.getAbsolutePath();
        } else {
            return "";
        }
    }

    @Override
    public String toString() {
        return "SerialPort{" +
                "name='" + name + '\'' +
                ", root='" + root + '\'' +
                ", file=" + file +
                '}';
    }
}
